package com.wangjiacai.utils.cos;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.region.Region;

public class CosRepository {

    private String secretId;
    private String secretKey;
    private String region;
    private COSCredentials cred;
    private ClientConfig clientConfig;
    private static COSClient cosClient;

    public CosRepository(String secretId, String secretKey, String region) {
        this.secretId = secretId;
        this.secretKey = secretKey;
        this.region = region;
        this.cred = new BasicCOSCredentials(secretId, secretKey);
        this.clientConfig = new ClientConfig(new Region(region));
    }

    public COSClient getCosClient() {
        if(cosClient!=null) return cosClient;
        this.cosClient=new COSClient(cred, clientConfig);
        return cosClient;
    }
}
